<%@ page contentType="text/html; charset=utf-8"%>

<div id="rawDataDiv" style="width: 100%;">



	<div>
		<span style="margin-top: 16px;">开始时间：</span><input type="text"
			id="rawDataStartDate" style="margin-top: 7px;"> <span
			style="margin-top: 16px;">结束时间：</span><input type="text"
			id="rawDataStopDate" style="margin-top: 7px;"> 
			<select id="selectRawTestType" onchange="rawDataTypeChange(this)" style="margin-top: 7px; height: 28px; font-size: 14px;z-index: 1;">
			<option value="网页测试">网页测试</option>
			<option  value="下载测试">下载测试</option>
		</select> 
		<input id="companyText" type="text" style="width: 200px;margin-top: 7px;display: none;"></input>
		 <select id="companySelect" onchange="t(this)"
			style="margin-top: 7px; height: 28px; font-size: 14px;z-index: 1;">
			<option selected="selected" value="所有">所有数据</option>
			<option id="urlItm" value="测试网址">测试网址</option>
			<option value="宽带账号">宽带账号</option>
			<option value="宽带套餐">宽带套餐</option>
			<option value="VlanID1">VlanID1</option>
			<option value="VlanID2">VlanID2</option>
		</select> 
		<input type="button" style="width: 100px;"
			class="btn btn-primary m_r" onclick="getRawData()" value="查询"/>

		<input type="button" onclick="ExportReportRaw()" style="width: 100px;" class="btn btn-primary m_r"
			value="导出报表"></input>
	</div>
	<div>

		<table class="table table-striped table-bordered" id="rawDataTable">

		</table>

	</div>
	<div
		style="margin: 0 auto; width: 700px; text-align: center; font-size: 14px;">

		<a href="#" onclick="upRawPage()">上页</a><a href="#"
			style="margin-left: 10px;" onclick="downRawPage()">下页</a> <input
			id="nowPageNumber" type="text"
			style="width: 30px; margin-left: 10px;" value="1"> /<span
			id="rawPageCount">0</span> <a href="#" style="margin-left: 10px;"
			onclick="nowPage()">跳转</a>

	</div>
</div>

<script>

function rawDataTypeChange(obj){
	
	if (obj.value == "下载测试") {
		
		var str='<option selected="selected" value="所有">所有数据</option>';
		str+='<option value="宽带账号">宽带账号</option>';
		str+='<option value="宽带套餐">宽带套餐</option>';
		str+='<option value="VlanID1">VlanID1</option>';
		str+='<option value="VlanID2">VlanID2</option>';
		$("#companySelect").html(str);
		$("#companyText").hide();
		getRawData();
	} else{
		var str='<option selected="selected" value="所有">所有数据</option>';
		str+='<option  value="测试网址">测试网址</option>';
		str+='<option value="宽带账号">宽带账号</option>';
		str+='<option value="宽带套餐">宽带套餐</option>';
		str+='<option value="VlanID1">VlanID1</option>';
		str+='<option value="VlanID2">VlanID2</option>';
		$("#companySelect").html(str);
		$("#companyText").hide();
		getRawData();
	}
}

	function t(obj) {
		if (obj.value == "所有") {
			$("#companyText").hide();
		} else{
			$("#companyText").show();
		}
	}

	var rawDataStartDate, rawDataStopDate, companySelect, companyText,selectTestType, pageNumber, pageCount;

	function upRawPage() {

		if ((pageNumber - 1) > 0) {
			pageNumber = pageNumber - 1;

			$.post("getData", {
				"types" : "rawData",
				"rawDataStartDate" : rawDataStartDate,
				"rawDataStopDate" : rawDataStopDate,
				"companySelect" : companySelect,
				"selectRawTestType" : selectTestType,
				"pageNumber" : pageNumber,"companyText":companyText
			}, function(data) {
				setRawData(data);
			}, "json");

		}

	}
	function downRawPage() {

		if ((pageNumber + 1) <= pageCount) {

			pageNumber = pageNumber + 1;

			$.post("getData", {
				"types" : "rawData",
				"rawDataStartDate" : rawDataStartDate,
				"rawDataStopDate" : rawDataStopDate,
				"companySelect" : companySelect,
				"selectRawTestType" : selectTestType,
				"pageNumber" : pageNumber,"companyText":companyText
			}, function(data) {
				setRawData(data);
			}, "json");

		}

	}
	function nowPage() {

		if (parseInt($("#nowPageNumber").val()) <= pageCount
				&& parseInt($("#nowPageNumber").val()) > 0) {

			pageNumber = parseInt($("#nowPageNumber").val());

			$.post("getData", {
				"types" : "rawData",
				"rawDataStartDate" : rawDataStartDate,
				"rawDataStopDate" : rawDataStopDate,
				"companySelect" : companySelect,
				"selectRawTestType" : selectTestType,
				"pageNumber" : pageNumber,"companyText":companyText
			}, function(data) {
				setRawData(data);
			}, "json");

		}

	}

	$(function() {
		$("#rawDataStartDate").datepicker();
		$("#rawDataStopDate").datepicker();
		iniRawData();
	});

	function setRawData(data) {

		var tableVal;

		var dataLen;

		if (pageNumber == 1) {

			dataLen = data.length - 1;
			pageCount = data[(data.length - 1)];
			$("#rawPageCount").html(pageCount);

		} else {

			dataLen = data.length;
		}

		$("#nowPageNumber").val(pageNumber);

		if (selectTestType == "网页测试") {

			tableVal = "<thead><tr><th>ID</th><th>测试网址</th><th>平均时延</th><th>最大时延</th><th>最小时延</th>"
					+ "<th>丢包率</th><th>抖动</th><th>测试次数</th><th>用户帐号</th><th>宽带套餐</th> <th>用户IP</th>"
					+ " <th>VlanID1</th> <th>VlanID2</th><th>测试时间</th></tr></thead><tbody >";
			for ( var i = 0; i < dataLen; i++) {

				var obj = data[i];

				tableVal = tableVal
						+ "<tr><td>"
						+ obj.indexe
						+ "</td><td>"
						+ obj.url
						+ "</td><td>"
						+ obj.timedelayAvr
						+ "ms</td><td>"
						+ obj.timedelayMax
						+ "ms</td>"
						+ "<td>"
						+ obj.timedelayMin
						+ "ms</td><td>"
						+ obj.lostRate
						+ "%</td>"
						+ "<td>"
						+ obj.shake
						+ "</td><td>"
						+ obj.testCount
						+ "</td>"
						+ "<td>"
						+ obj.userNumber
						+ "</td><td>"
						+ obj.bSize
						+ "</td>"
						+ "<td>"
						+ obj.intranetIp
						+ "</td><td>"
						+ obj.vlanId1
						+ "</td><td>"
						+ obj.vlanId2
						+ "</td>"
						+ "<td>"
						+ date2str(new Date(obj.cmdTime.time),
								"yyyy-MM-dd hh:mm:ss") + "</td></tr></tbody>";
			}

		} else if (selectTestType == "下载测试") {

			tableVal = "<thead><tr><th>ID</th><th>平均速度</th><th>最大速度</th><th>最小速度</th>"
					+ "<th>用户帐号</th><th>宽带套餐</th> <th>用户IP</th>"
					+ " <th>VlanID1</th> <th>VlanID2</th><th>测试时间</th></tr></thead><tbody >";
			for ( var i = 0; i < dataLen; i++) {

				var obj = data[i];

				tableVal = tableVal
						+ "<tr><td>"
						+ obj.indexe
						+ "</td><td>"
						+ obj.speedAvr
						+ "KB/s</td><td>"
						+ obj.speedMax
						+ "KB/s</td>"
						+ "<td>"
						+ obj.speedMin
						+ "KB/s</td>"
						+ "<td>"
						+ obj.userNumber
						+ "</td><td>"
						+ obj.bSize
						+ "</td>"
						+ "<td>"
						+ obj.intranetIp
						+ "</td><td>"
						+ obj.vlanId1
						+ "</td><td>"
						+ obj.vlanId2
						+ "</td>"
						+ "<td>"
						+ date2str(new Date(obj.cmdTime.time),
								"yyyy-MM-dd hh:mm:ss") + "</td></tr></tbody>";
			}

		}

		$("#rawDataTable").html(tableVal);

	}

	function date2str(x, y) {
		var z = {
			M : x.getMonth() + 1,
			d : x.getDate(),
			h : x.getHours(),
			m : x.getMinutes(),
			s : x.getSeconds()
		};
		y = y.replace(/(M+|d+|h+|m+|s+)/g, function(v) {
			return ((v.length > 1 ? "0" : "") + eval('z.' + v.slice(-1)))
					.slice(-2)
		});
		return y.replace(/(y+)/g, function(v) {
			return x.getFullYear().toString().slice(-v.length)
		});
	}

	function ExportReportRaw() {

		//getRawData();

		if (rawDataStartDate == "" || rawDataStopDate == ""
				|| rawDataStopDate == null || rawDataStartDate == null) {

			return;
		}
		showCommonDiv();
		$.post("exportReport", {
			"types" : "rawData",
			"rawDataStartDate" : rawDataStartDate,
			"rawDataStopDate" : rawDataStopDate,
			"companySelect" : companySelect,
			"selectRawTestType" : selectTestType,
			"pageNumber" : pageNumber,"companyText":companyText
		}, function(data) {
			closeCommonDiv();
			if (data != "false") {
				window.location.href = "exportReport?types=downFile&&fileName="
						+ data;
			}
		}, "json");

	}

	function iniRawData() {

		$("#rawDataStartDate").val(date2str(new Date(), "yyyy-MM-dd"));
		$("#rawDataStopDate").val(date2str(new Date(), "yyyy-MM-dd"));

		getRawData();
	}

	function getRawData() {

		rawDataStartDate = $("#rawDataStartDate").val();
		rawDataStopDate = $("#rawDataStopDate").val();
		pageNumber = 1;
		selectTestType = $("#selectRawTestType").val();
		companySelect = $("#companySelect").val();
		companyText = $("#companyText").val();
		if (rawDataStartDate == "" || rawDataStopDate == ""
				|| rawDataStopDate == null || rawDataStartDate == null) {

			alert("请选择时间段");
			return;
		}
		showCommonDiv();
		$.post("getData", {
			"types" : "rawData",
			"rawDataStartDate" : rawDataStartDate,
			"rawDataStopDate" : rawDataStopDate,
			"companySelect" : companySelect,
			"selectRawTestType" : selectTestType,
			"pageNumber" : pageNumber,"companyText":companyText
		}, function(data) {
			closeCommonDiv();
		
				
				setRawData(data);
		
			
		}, "json");

	}
</script>